/*
 * memory.h
 *
 * memory managemnet
 *
 */

#ifndef __MEMORY_H_
#define __MEMORY_H_

#ifdef  __cplusplus
extern "C" {
#endif		/* __cplusplus */

//#include "command_data.h"
#include "gps.h"
#include "gpsfix.h"
#include "command_data.h"
#include "imu_process.h"
  

#define MEMORY_START		0x20000000
/* Library use */
#define FLAG_MEM_START		MEMORY_START
#define FLAG_SIZE			0x10
#define GPS_DATA_START		(FLAG_MEM_START + FLAG_SIZE)
#define GPS_DATA_SIZE		sizeof(UBX_DATA)    //sizeof(GPS_DATA)
#define CMD_DATA_START		(GPS_DATA_START + GPS_DATA_SIZE)
#define CMD_DATA_SIZE		sizeof(CMD_DATA)
#define CONSOLE_TX_START	(CMD_DATA_START + CMD_DATA_SIZE)
#define CONSOLE_TX_SIZE		128
#define CONSOLE_RX_START	(CONSOLE_TX_START + CONSOLE_TX_SIZE)
#define CONSOLE_RX_SIZE		128
#define GPS_TX_START		(CONSOLE_RX_START + CONSOLE_RX_SIZE)
#define GPS_TX_SIZE			128
#define GPS_RX_START		(GPS_TX_START + GPS_TX_SIZE)
#define GPS_RX_SIZE			128
#define GPS_NMEA_START		(GPS_RX_START + GPS_RX_SIZE)
#define GPS_NMEA_SIZE		128
#define GSM_TX_START		(GPS_NMEA_START + GPS_NMEA_SIZE)
#define GSM_TX_SIZE			128
#define GSM_RX_START		(GSM_TX_START + GSM_TX_SIZE)
#define GSM_RX_SIZE			128
#define ELM327_TX_START		(GSM_RX_START + GSM_RX_SIZE)
#define ELM327_TX_SIZE		128
#define ELM327_RX_START		(ELM327_TX_START + ELM327_TX_SIZE)
#define ELM327_RX_SIZE		128
#define IMU_DATA_START		(ELM327_RX_START + ELM327_RX_SIZE)
#define IMU_DATA_SIZE		sizeof(IMU_DATA)
#define CON_INPUT_START		(IMU_DATA_START + IMU_DATA_SIZE)
#define CON_INPUT_SIZE		256
#define CON_RESP_START		(CON_INPUT_START + CON_INPUT_SIZE)
#define CON_RESP_SIZE		128
#define GPRS_RESP_START		(CON_RESP_START + CON_RESP_SIZE)
#define GPRS_RESP_SIZE		128
#define SMS_RESP_START		(GPRS_RESP_START + GPRS_RESP_SIZE)
#define SMS_RESP_SIZE		128
#define FLASH_DATA_START	(SMS_RESP_START + SMS_RESP_SIZE)
#define FLASH_DATA_SIZE		256
#define SMS_RX_PDU_START	(FLASH_DATA_START + FLASH_DATA_SIZE)
#define SMS_RX_PDU_SIZE		330
#define SMS_RX_DATA_START	(SMS_RX_PDU_START + SMS_RX_PDU_SIZE)
#define SMS_RX_DATA_SIZE	512
#define SMS_TX_PDU_START	(SMS_RX_DATA_START + SMS_RX_DATA_SIZE)
#define SMS_TX_PDU_SIZE		330 * 4
#define GPRS_RX_DATA_START	(SMS_TX_PDU_START + SMS_TX_PDU_SIZE)
#define GPRS_RX_DATA_SIZE	1460

#define MEMORY_END			(GPRS_RX_DATA_START + GPRS_RX_DATA_SIZE)



extern unsigned char *pFlag_Byte_0;		///< cargo power status
extern unsigned char *pFlag_console_tx_busy;
extern unsigned char *pFlag_modem_pt;
extern unsigned char *pFlag_err_flash;
extern unsigned char *pFlag_sys_para_rdy;
extern unsigned char *pFlag_gsm_sms_in;
extern unsigned char *pFlag_msg_res_print;
extern unsigned char *pFlag_err_msg_rx;
extern unsigned char *pFlag_err_flash_rw;

extern unsigned char *pFlag_Byte_1;
extern unsigned char *pFlag_pwr_flash;
extern unsigned char *pFlag_spi_busy;
extern unsigned char *pFlag_err_flash_timeout;
extern unsigned char *pFlag_agps_connect;
extern unsigned char *pFlag_wait_ubx_ack;
extern unsigned char *pFlag_UBX_protocol;
extern unsigned char *pFlag_NMEA_protocol;
extern unsigned char *pFlag_no_ubx_cmd;

extern unsigned char *pFlag_Byte_2;
extern unsigned char *pFlag_wait_ubx_cmd;
extern unsigned char *pFlag_sec_update;
extern unsigned char *pFlag_gps_off;
extern unsigned char *pFlag_pwr_gps;
extern unsigned char *pFlag_gps_tx_busy;
extern unsigned char *pFlag_rtc_update;
extern unsigned char *pFlag_gps_data;
extern unsigned char *pFlag_gps_agps_fix;

extern unsigned char *pFlag_Byte_3;
extern unsigned char *pFlag_gps_fix;
extern unsigned char *pFlag_agps_update;
extern unsigned char *pFlag_ELM327_wait_res;
extern unsigned char *pFlag_gps_change_potocol;
extern unsigned char *pFlag_NMEA_char_occur;
extern unsigned char *pFlag_ELM327_ready;
extern unsigned char *pFlag_elm327_tx_busy;
extern unsigned char *pFlag_pps_debug;


extern unsigned char *pFlag_gps_nmea_print;     // *pFlag_Byte_4

extern unsigned char *pFlag_Byte_5;
extern unsigned char *pFlag_pps_trigger;
extern unsigned char *pFlag_adxl345_offset_set;
extern unsigned char *pFlag_l3g4200d_offset_set;
extern unsigned char *pFlag_pps_next;
extern unsigned char *pFlag_angleSH_output;
extern unsigned char *pFlag_gps_power_on;
extern unsigned char *pFlag_gsm_power_on;
extern unsigned char *pFlag_magnetometer_bias_set;

extern unsigned char *pFlag_Byte_6;
extern unsigned char *pFlag_gpsfix_now_temp;
extern unsigned char *pFlag_gpsfix_last_temp;
extern unsigned char *pFlag_magnetometer_static;
extern unsigned char *pFlag_gsm_uart_tx_busy;

extern unsigned char *pFlag_Byte_7;

extern unsigned char *pFlag_Byte_8;

extern unsigned char *pFlag_Byte_9;

extern unsigned char *pFlag_Byte_10;

extern unsigned char *pFlag_Byte_11;

extern unsigned char *pFlag_Byte_12;

extern unsigned char *pFlag_Byte_13;

extern unsigned char *pFlag_Byte_14;

extern unsigned char *pFlag_Byte_15;


/** @name Global variable
 * @{
 */
extern unsigned long gSystick;	///< system tick counter base: SYS_TICK * 1ms
extern unsigned long gRTCSec;	///< RTC counter base 1 second
extern unsigned long gSystick_1ms;  //fenris 1ms
extern unsigned long get_data_time;
extern unsigned short mircoSec;
extern GPS_DATA *pGPS;			///< gps NMEA Code data pointer
extern UBX_DATA *pUBX;          ///< gps UBX Data           //fenris 20101214
extern CMD_DATA *pCMD;			///< Command data pointer
extern char *pConsoleTxData;
extern char *pConsoleRxData;
extern char *pGPSTxData;
extern char *pGPSRxData;
extern char *pGPSNMEAData;
extern char *pGSMTxData;
extern char *pGSMRxData;
extern char *pELM327TxData;
extern char *pELM327RxData;
extern char *pConInputData;
extern char *pConRespData;
extern char *pGPRSRespData;
extern char *pSMSRespData;
extern unsigned char *pFlashData;
extern char *pSMSTxPDUData;
extern char *pSMSRxData;
extern char *pGPRSRxData;
extern char *pSMSRxPDUData;
extern IMU_DATA *pIMU;

extern unsigned char gTaskMaxUse;
extern unsigned char gTaskJoinNum;					///< task number in queue
extern unsigned long gODOMeter;

extern unsigned long Get_Systick(void);
/** @} */

#ifdef __cplusplus
}
#endif	/* __cplusplus */
#endif	/* __MEMORY_H_ */
/** @} */